<template>
	<view>
		<view>
			<view class="nav-item flex align" @click="toScan()">
				<image src="/static/shops/icon1.png"></image>
				<view>扫码核销</view>
			</view>
			<view class="nav-item flex align" @click="toRecord()">
				<image src="/static/shops/icon5.png"></image>
				<view>核销记录</view>
			</view>
			<view class="nav-item flex align" @click="toLogin()">
				<image src="/static/shops/icon4.png"></image>
				<view>退出登录</view>
			</view>
		</view>
	</view>
</template>

<script>
	import wx from 'weixin-js-sdk'
	import {
		tourMerchantDetail,
		tourMerchantLogout,
		config
	} from '@/api/apiData.js';
	export default {
		data() {
			return {};
		},
		mounted() {
			this.getInfo()
			this.initWxConfig()
		},
		methods: {
			// 扫码
			toScan() {
				wx.scanQRCode({
					needResult: 1,
					onlyFromCamera: true,
					scanType: ["qrCode"], // 可以指定扫二维码还是条形码
					success(res) {
						if (res.resultStr != '') {
							uni.navigateTo({
								url: '/pages/integral/manageResult?no=' + res.resultStr,
							})
						}
					}
				})
			},
			async initWxConfig() {
				const result = await config()
				if (result.code == 1) {
					wx.config({
						debug: result.data.debug, // 生产环境设置为 false
						appId: result.data.config.appId,
						timestamp: result.data.config.timestamp,
						nonceStr: result.data.config.nonceStr,
						signature: result.data.config.signature,
						jsApiList: result.data.config.jsApiList,
						openTagList: ['wx-open-launch-weapp']
					});

					wx.ready(() => {
						// alert("微信 JS SDK 已就绪");
					});

					wx.error((err) => {
						// alert("微信 JS SDK 配置错误：", err);
					});
				} else {

				}


			},
			async getInfo() {
				const result = await tourMerchantDetail()
				if (result.code == 1) {

				} else {
					uni.redirectTo({
						url: '/pages/integral/manageLogin'
					})
				}

			},
			toRecord() {
				uni.navigateTo({
					url: '/pages/integral/manageRecord'
				})
			},
			toLogin() {
				this.logout()
				uni.redirectTo({
					url: '/pages/integral/manageLogin'
				})
			},
			async logout() {
				const result = await tourMerchantLogout()
			},
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background: #F7F6F9;
	}

	.nav-item {
		background: white;
		padding: 20rpx;
		margin: 20rpx 30rpx;
		font-size: 26rpx;
		font-weight: bold;
	}

	.nav-item image {
		width: 86rpx;
		height: 86rpx;
		margin-right: 20rpx;
	}
</style>